package com.zjht.gmcc.servlet.sys;

import java.io.PrintWriter;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.util.MyJDBC;


public class ParameterEdit extends BaseServlet {

	private static final long serialVersionUID = 1L;

	public boolean process(HttpServletRequest request, HttpServletResponse response,HttpSession session, PrintWriter out, MyJDBC myJDBC,  String menu)throws Exception {
		int i_flag = 0;

		String s_parenmeterid = request.getParameter("parenmeterid");
		// String s_zcsid = request.getParameter("zcsid");//�û�����主参数名称
		String s_zcsname = request.getParameter("zcsname");
		int Iicount = Integer.parseInt(request.getParameter("icount").toString());

		String url = "/sys/parameter/parametermx.jsp?paraid=" + s_parenmeterid;
		//StringBuilder html = new StringBuilder();
		
		String s_sql = null;
		PreparedStatement ps = null;

		s_sql = "update parameter set paraname=? where paraid=?";
		ps = myJDBC.prepareStatement(s_sql);
		ps.setString(1, s_zcsname);
		ps.setString(2, s_parenmeterid);
		ps.executeUpdate();
		s_sql = null;
		ps.close();
		ps = null;
		int i;

		String Ssubparaid, Ssubparaname;
		s_sql = "update parameter set paraname = ? where parentid = ? and paraname = ?";
		ps = myJDBC.prepareStatement(s_sql);

		for (i = 1; i <= Iicount; i++) {
			Ssubparaid = request.getParameter("subparaid" + Integer.toString(i)).toString();
			Ssubparaname = request.getParameter("subparaname" + Integer.toString(i)).toString();

			ps.setString(1, Ssubparaname);
			ps.setString(2, s_parenmeterid);
			ps.setString(3, Ssubparaid);
			i_flag = ps.executeUpdate();

			if (i_flag == 0) {
				break;
			}
		}

		s_sql = null;
		ps.close();
		ps = null;

		String act = "参数修改";
		if (i_flag >0) {
			alert(out, act + "成功",url);
		} else {
			errAlert(request, out, menu, act + "失败");
		}
		return i_flag > 0;
		
	}
}
